<?php

namespace App\Console\Commands;

use App\Models\Agent;
use App\Models\Partner;
use Illuminate\Support\Collection;

class RecalculateTheAffiliatedPartner extends ForEachAllAgents
{
    /**
     * 命令名称及签名
     *
     * @var string
     */
    protected $signature = 'migrate:recalculate_the_affiliated_partner {agent_ids}';

    /**
     * 命令描述
     *
     * @var string
     */
    protected $description = '重新计算所属合伙人';

    public function handle()
    {
        // 2021-01-05 00:10:51 准备重新计算, 如下 agent_id
        // 接收需要重新计算所属合伙人的代理商 IDs
        $agentIds = array_filter(array_unique(explode(',', $this->argument('agent_ids'))));
        empty($agentIds) && $this->output->error('请输入代理商 IDs');

        // 当前存在的合伙人
        $currentPartnerIds = Partner::query()->pluck('agent_id')->toArray();

        // 代理商上级路径上的合伙人身份
        $bar = $this->output->createProgressBar(count($agentIds));
        $bar->start();

        $agentIds = new Collection($agentIds);
        $agentIds->chunk(100)->each(function ($agentIdChunk) use ($currentPartnerIds, $bar) { // 拆成 100 个一查询
            $agentChunkList = Agent::query()->findMany($agentIdChunk, ['id', 'parent_path_id', 'affiliated_partner']);
            $agentChunkList->each(function ($agent) use ($currentPartnerIds, $bar) { // 遍历单个代理
                $agentParentPathIds = array_reverse( // 最后要翻转一下,因为 上级到下级从前到后 eg: 10-4650-23866-45421
                    array_filter(array_unique(explode('-', $agent['parent_path_id'] ?? '')))
                );

                foreach ($agentParentPathIds as $parentAgentId) { // 这里从最近的上级开始判断 是否属于 合伙人, 如果是则 更新所属合伙人
                    if (in_array((int) $parentAgentId, $currentPartnerIds, true)) {
                        Agent::query()->where('id', $agent->id)->update(['affiliated_partner' => $parentAgentId]);
                        break;
                    }
                }

                $bar->advance(1);
            });
        });

        // 49946,50823,48786,50148,48502,49935,50047,50566,50791,51367,48531,47238,50873,49925,48160,47280,50722,49980,51284,49689,50560,49794,50973,50282,50603,50210,49121,51200,49328,49821,47256,47778,48798,49251,50239,50246,50724,48271,50687,48269,47172,50834,47504,48011,47824,49554,47628,48172,48835,48994,51013,48036,48642,50364,50502,50211,51560,50533,51376,50216,50842,48350,47735,49985,50438,51134,49655,47786,50669,51070,50676,49114,51305,50746,49740,50659,50728,51279,47336,50660,49994,47787,51436,47254,49260,48275,51394,48438,51255,49374,50487,51189,51339,51393,51107,51211,48843,49861,48168,51443,49764,49128,50113,51253,48314,51561,49253,47731,47503,48013,47749,49163,51398,50721,50286,47970,50658,48706,50057,47360,50030,46878,50363,50779,47394,50610,47364,48658,48844,50395,50097,51350,50668,48460,49406,50576,48040,48555,51276,47995,49837,50388,49888,48784,50195,48004,50879,50457,46885,51222,49352,49735,50694,49913,49971,48044,47435,49737,50814,51459,49650,48842,47548,49836,47278,50477,49310,51196,49992,46941,50280,48402,49420,47220,50132,47791,51060,50846,51346,49713,49915,49729,49997,50836,50977,51275,48114,51005,51084,49853,50711,48846,48100,50258,50750,49771,50935,47370,48613,49548,51483,48582,48010,51028,49736,50010,47329,51142,50325,50986,51352,51206,49970,50485,51351,48565,51248,51292,48551,49535,49546,50620,51290,50297,51011,48705,51068,51121,50684,49601,48161,50102,48395,50133,50480,50518,50850,50389,50386,50011,49550,50716,49119,47777,48689,48797,50358,48170,49873,49674,50837,48646,49805,48811,50002,46979,50127,51278,50238,51265,50473,50729,50624,49314,50201,48907,47693,50622,48558,50309,49701,49372,48514,50835,48800,47642,51384,50322,46884,49804,49765,51032,48552,48178,51192,49677,47178,47442,51354,51497,46981,51261,51301,50796,50178,48351,48910,50346,48513,51210,50392,51318,49877,51460,50607,48440,48757,48266,46765,49719,49676,48222,50525,51238,47290,51535,50476,51439,47262,51453,50820,50306,48813,50273,50803,48428,47606,47291,47371,50859,50882,47040,51150,50768,49981,51012,50278,48088,47927,50186,50509,49123,49784,51101,51179,51342,49407,49424,49899,49224,49747,47069,50564,49927,50967,50275,49851,51314,50674,49680,49553,46917,48158,48267,49672,50748,50314,49635,49293,51333,51437,51226,48563,51559,50641,50565,47528,49662,50380,46891,51449,51324,50324,48280,47331,49801,48401,51204,46810,50839,51418,49996,50160,48416,50058,50957,50287,50900,47745,51341,49835,50075,50519,49901,50945,51387,50025,49307,49322,49216,51423,51167,49653,48567,47901,49709,49960,50347,50137,48020,51445,51540,48083,50542,48445,47724,51444,51073,50618,50975,48239,49900,50555,48704,50198,51390,49742,49773,50965,47736,48362,50368,51304,50636,50655,50111,47637,47997,47501,51277,50933,50950,50436,50156,47892,51000,50522,51472,49858,50595,50372,50538,50592,51034,48568,50539,48826,48296,50411,50164,50248,51406,48246,48442,51085,49929,50954,46921,50493,48649,49708,50257,50978,50401,48995,48156,51386,51006,49844,51311,48057,49723,51337,47928,49949,50531,50391,49945,48644,50490,50999,50381,49118,51543,49687,51369,50864,49652,51400,50103,50019,50444,49542,51056,51548,49721,49693,50520,50093,50789,51146,49645,49741,50441,50816,49906,48747,49749,48313,49909,49824,48096,49916,47900,51205,50517,50897,51514,48915,51007,48788,51257,48714,51055,46929,49569,48091,50841,49685,47311,50176,49319,50824,50446,50291,50237,49746,47873,48288,48834,48634,48173,51557,50534,48637,51133,50106,46824,50354,49731,49412,50279,47627,49433,48441,47888,49921,48126,47746,50139,50051,50972,51556,49953,47173,48561,48520,49624,51530,50956,48489,49867,50512,51327,50775,49859,49939,50048,48026,51332,51110,50403,49633,50104,50046,50241,47279,51417,51103,50331,48908,51254,47930,50375,50447,50588,47825,48050,51296,51289,50652,48278,49807,51092,50672,50709,49690,51064,48108,51534,49758,50040,50081,51159,48700,49830,49876,50812,50573,50454,49241,47610,47747,50105,50463,49880,49788,49917,50206,48236,51335,50266,50581,51203,48054,48680,49252,48645,47335,50351,49982,50865,47641,51190,50530,49715,49857,48252,51114,50124,48311,49862,48397,51358,51424,47502,48365,49172,46875,50488,48812,48854,50855,50912,50008,47779,48145,48032,48191,49429,48146,50818,47193,50328,50675,48133,49698,48305,50854,50562,50244,50710,51269,50987,51027,47045,50780,50232,51197,48353,50732,49904,49878,47622,48099,50479,47992,47744,51343,51147,48384,50107,50905,50202,50571,50296,51136,50632,50317,49910,49220,50131,47729,50041,49717,51464,49756,49704,49914,51160,51527,48694,50374,48625,50510,50049,49869,49099,48150,51245,50523,49545,51377,50451,51317,48038,47046,51239,51555,50992,50227,47891,50587,50851,50136,49963,50706,50141,48858,49644,51538,48681,49732,51019,49670,48703,50083,47717,49459,50366,51105,49649,50924,50453,48626,48503,50916,51461,48124,50521,50299,51456,46762,49361,49724,50413,48104,48002,50988,49654,48796,48075,50225,50650,50621,50285,50942,50984,49539,48856,49819,49871,49411,50442,48094,49547,50544,50631,51287,47926,50515,49335,47615,50744,50871,50199,48508,51413,49325,51009,47196,51038,48355,48261,50308,49977,50260,51008,50507,51128,51378,48095,50617,48051,50038,50616,50605,50412,49291,51061,48176,50336,49969,51457,48049,48821,49931,47640,49324,49823,47547,51316,48434,50549,51227,49533,48097,48127,47638,51119,48653,51306,50881,50619,50585,50649,49315,51087,51223,50505,48029,51383,51329,49816,48225,50384,51336,50234,50886,50370,47277,48398,50376,48265,50183,50596,48617,49306,47282,50319,51452,48234,47373,49820,51042,50207,47289,47505,50536,51518,50452,50781,46887,48677,51232,49430,50735,49922,48871,50067,46889,48195,49828,50895,50550,49829,48325,50123,51470,46967,49879,50337,47886,49457,49646,49811,51116,51151,48837,48152,49872,48308,50462,49669,47479,51129,50810,50580,49609,50876,51500,50691,47635,48312,47216,50121,50335,51030,49792,49628,48060,49663,49838,50003,51553,47893,51446,48043,51489,51049,50579,51474,49744,51466,49329,48426,46750,50808,50792,47991,50209,50158,47609,51131,51026,48118,49620,51174,50778,50514,49330,50406,48560,47823,50527,50289,47478,47776,47748,49845
        // 51122,51214,50840,47872,48055,51173,49866,49952,50055,50220,48000,50461,50643,50805,50894,51224,50798,51130,50100,50170,50294,51388,51544,49694,49636,48999,50657,48089,49549,48162,50240,47223,51270,48125,51348,51455,51334,49365,51234,51517,51021,49772,50074,49691,49127,51300,47718,48920,49714,50913,49924,50367,50400,49431,49366,50553,50432,48909,50254,50495,50419,50690,47224,47190,51091,49814,47188,51414,50312,50348,49789,50908,51236,51397,49734,47980,50574,49722,50787,49627,50680,51319,51409,50378,49911,50032,47935,49989,48303,51353,47037,48759,49551,49933,48322,51303,48614,48309,47924,51429,50811,50642,51059,50269,48028,48616,51208,49893,50667,50776,51479,50664,50832,50344,48165,50771,47168,51218,50981,51486,50689,49940,49898,50868,48337,49752,50414,48102,51113,51490,51138,51263,51422,51371,50316,49543,51469,51536,47837,51550,50042,49544,48431,48056,49575,50828,49364,51258,50858,49793,50590,49856,50393,49666,51381,49930,48366,49657,51328,48651,48562,48519,47969,50915,50976,50919,51326,49779,49460,51194,50730,51001,50714,49896,51215,50115,50783,50053,51120,49222,50253,49660,50307,49327,50281,47066,48864,51244,50117,50110,49974,49937,47286,48422,50958,48008,51481,48517,48333,48229,48194,50383,51440,51477,50318,51163,51504,51212,48164,51041,48417,51181,48386,51487,46855,51313,47515,48919,50435,50699,51546,50157,50704,49671,48702,51360,48424,49938,48419,51532,51170,50985,50174,51427,50078,50161,50695,50087,50692,47790,46962,51488,50311,50094,50540,50635,49999,48087,50554,47722,49098,48221,48144,48521,49761,48675,50793,50994,49432,51433,48801,48794,51183,48840,50698,50264,49625,49463,50203,47788,47395,49673,47258,51375,47294,51505,49892,48648,50004,48107,49682,50256,49800,49902,48373,50757,51322,51454,49426,50026,50353,51083,49868,51482,50870,46958,50853,50693,49332,51157,49803,50229,50804,49331,50155,50989,47936,49405,50482,50777,49679,48166,50334,51320,49215,47261,49745,50902,48243,50583,51102,49926,49602,51230,50867,47269,48627,48053,49173,50467,49908,49725,51237,51435,50613,50831,50475,50558,50460,51528,47441,49833,47383,50717,51094,51100,49995,51462,50471,50843,50848,50052,46961,50397,50492,47792,49795,48427,49750,51177,50683,50742,51262,50061,51415,47727,48115,47214,50236,50062,50274,48695,49626,48878,51106,50015,47332,49634,48033,50802,49360,49362,51058,49642,49579,48464,51247,48527,50747,50483,50708,51268,50983,50177,50772,48789,50745,51098,50940,49320,48292,50409,47330,48488,49991,50222,50080,51385,50741,50417,49843,51267,48832,49639,49887,50615,50938,46763,50602,49813,50979,47428,50715,48031,49968,49990,48171,50899,49413,50407,50054,50009,50000,50263,48323,46943,51125,47874,48331,50688,49622,50034,48880,48151,49718,49778,48223,50465,49942,48618,51127,51425,48458,49455,50541,51494,48179,50031,47213,48215,49313,51080,47259,49219,50076,50701,50472,50914,51428,50208,49686,48364,51554,50315,49126,48862,51024,49998,48825,48113,50734,51298,50418,50486,50089,46874,48986,50045,50498,49402,50013,51096,51240,50394,50218,49831,51361,48157,47316,50196,50966,50217,50140,51458,49353,50357,47925,50249,51187,48174,47270,50226,48237,49988,48430,50129,47372,51145,50838,51315,47221,50600,50027,51508,49832,48385,51467,50484,50645,51293,50878,50939,48600,50609,51144,49716,49884,51063,48399,50703,49776,48643,48335,48101,47295,49333,47393,50304,50017,51541,47750,47480,50707,46764,48175,51420,51195,50272,50646,48289,50193,47049,51516,50033,51152,48058,49131,51432,50733,48447,51522,48291,48524,50980,50903,48079,48136,48985,48418,51228,51035,47312,46923,49568,51434,51426,49638,49959,51069,48518,50856,51199,49696,50911,47937,50943,50597,48352,51282,50723,48112,50200,49965,49753,50090,49570,50662,50424,47296,51299,51431,49641,51558,47534,48006,49154,49825,48921,50740,50797,50035,48756,49536,48189,51135,49599,51545,49748,51054,48148,49993,47195,49699,46927,50020,47315,48996,50892,50184,51539,51411,49976,51162,50276,51419,50270,50491,47988,50931,47643,49218,48380,47255,49170,50511,48511,48877,47347,51149,50474,50982,47287,51542,50551,50118,49675,50997,49841,50948,51186,47367,49936,46789,47794,48093,51365,51086,47438,50321,50822,48302,49987,50112,47201,49842,49681,48809,51294,48080,50922,51185,50633,50416,48282,51416,50665,50719,51512,47993,50926,50756,51123,50572,50215,49710,49643,50819,47210,50686,50247,50421,49755,49791,47836,51331,51281,49702,49818,50302,51280,50410,51140,48859,46883,47427,50599,50904,50144,47694,50396,49647,49113,49665,51366,51359,49806,51075,51442,50116,49317,51362,51309,50508,49826,50974,50752,48235,50727,50774,48474,50567,50611,50888,51523,47639,48782,46926,50194,49592,48806,49667,50661,50382,51345,46928,50428,48159,48436,49834,49316,51438,50561,51395,48516,47720,50415,47723,49948,50162,50670,47623,51285,48315,47215,51235,47398,51403,50766,48566,47725,48396,48134,51095,49757,49760,50298,51154,49521,48084,50697,50197,50875,48631,49827,50963,48435,47189,48270,50327,50420,47187,48103,49786,49743,47529,51302,50166,49907,51066,48678,50092,51220,48281,49615,50313,50095,49538,51344,49678,49790,48814,47719,48251,50455,49809,48343,51124,51217,51297,48135,49422,49334,50545,49703,51441,50146,51475,50937,50770,50860,49777,49120,47226,50332,51023,51484,50800,49897,50369,48746,51256,51071,50404,48659,48824,48874,49456,49375,50371,48463,48750,50578,47369,51401,51117,48916,48831,50532,48693,48523,50189,48679,50440,51078,47030,51450,50731,50679,50422,49711,50284,51349,50809,51526,48361,49428,50190,51029,50402,51225,50352,50349,51260,48827,47477,48238,48163,51052,49905,50497,49421,48324,49890,50559,50429,49895,50168,50563,49618,50623,50795,48462,50673,50496,50941,49727,50949,47382,50091,48610,50648,51141,51525,49983,48847,49410,48037,50713,49967,48306,50345,50552,49955,51178,46876,50861,51402,51148,51043,51396,51176,51448,47200,49863,51180,51062,47381,48092,49797,50235,48153,50122,51374,48147,51307,50339,47235,47375,50044,48268,48224,50825,47923,49852,51286,48655,48748,51164,51175,48799,51213,50970,50906,48085,50114,51201,47207,50293,51430,48450,47218,48290,50064,48787,49815,51382,49171,49951,50221,47301
        // 51158,49461,49537,50546,49957,50951,48078,50790,46942,50056,50149,50385,47174,48928,50720,50326,50016,51291,49886,51266,49321,51506,51109,50470,50953,48381,50128,48461,50765,51321,49326,48349,51391,51246,49600,50880,50644,51389,46890,48860,50320,51003,50586,50251,49425,51250,49423,50214,49336,50653,50506,47327,50223,48925,48687,47838,48319,50295,49591,48226,51241,51182,49619,51476,46766,50852,49236,50712,47889,47835,49903,47212,50608,51465,48429,51473,50228,47068,50068,51231,50625,49891,50755,50233,49403,50108,48758,49766,49808,48190,47630,48802,51373,50355,51533,49840,49928,51330,46790,49754,48276,51143,50529,50060,48839,48332,50088,50626,48245,49101,50705,50535,49787,50934,47734,51132,50920,50794,47260,50634,48926,51033,49167,50433,47979,50408,47366,50883,48820,48250,50459,49973,49961,48253,50356,51219,50142,51370,49580,48927,49684,50405,49632,50647,49870,48449,50612,49623,48510,51079,49309,51184,51002,50500,50678,48525,51039,51310,48188,50666,48564,47281,50930,49308,51074,46960,51357,49404,48512,50077,51111,48790,49656,47328,48155,49462,48833,50192,50373,48676,50928,50556,47726,50147,51065,48421,48632,50271,50762,49738,47775,50591,49695,46761,50844,48807,49864,50857,48293,49373,49947,50023,50568,51498,47608,50921,49733,50584,49664,49950,51308,51040,50577,50806,49912,47050,50037,50773,51379,48918,50084,47348,51515,50639,49975,48169,49810,51191,50231,47363,50443,51537,50629,50330,48553,50863,48059,48149,48042,49503,50171,50589,50159,51089,48387,50145,47890,48027,48509,49295,49780,50099,47365,51112,47350,50456,48803,48816,48116,51503,48998,50151,48451,48196,47887,47313,47240,49883,48785,50923,46925,48009,48077,49730,51088,50022,50292,50754,48808,51045,50098,50350,51412,50990,48383,48030,49775,48559,49363,47236,50005,50125,51485,51139,49847,51288,48005,50163,48817,48526,51016,50877,49958,47530,50073,51161,50288,51492,51168,50964,51510,49115,50204,50503,46983,51115,49882,51295,49648,50971,48139,49839,50815,48863,48838,50651,51407,48459,51198,49651,50925,50594,50101,50360,50359,50245,50606,48749,50050,50213,50758,51104,50784,49849,50582,49889,50753,48382,47191,50601,48086,50267,50423,48446,51169,48154,49604,51399,50627,49124,48577,50936,49956,50014,47895,49885,50119,51242,51372,49781,50445,46868,50126,49697,46748,51355,46879,49984,49668,48181,50827,48121,49799,47257,48433,48875,49540,50637,49263,50898,50043,50638,47728,49854,46881,47834,49894,46959,49122,48515,51499,46873,51410,50096,50323,48012,49541,47732,51340,48879,51031,50799,50962,47374,50466,49966,50890,51048,49414,49812,50743,47998,50086,48822,47237,50955,48106,48394,48273,50872,50134,47368,50063,46877,47194,48372,50458,48656,49296,50927,50901,49117,49427,50130,50343,48307,50569,51451,50874,48128,50663,47624,50430,49782,50543,49262,51478,49223,50885,49972,50398,50489,49986,50598,50224,50481,47358,48580,50751,51363,47617,48836,49943,50891,48354,51165,51524,49846,50365,50862,48024,50069,48123,48547,49552,50329,50120,49934,49920,50448,49567,46922,51312,50427,48320,50261,51249,49941,50085,51259,49932,50499,50528,47996,48274,50682,51501,51137,48444,50205,51408,50252,49116,50910,46888,48682,49683,50303,50154,50807,50656,50788,50896,47894,48363,49323,50959,51057,51529,49500,48818,51090,50175,51509,50537,51463,48007,50996,50300,49629,47362,50379,47793,50829,50961,50909,51325,49311,48657,49769,46749,47271,47972,50219,51221,50761,49762,51097,50449,51468,50907,50212,50431,47217,50991,50893,50165,50845,49770,47771,50726,48047,49918,49919,49312,51051,51207,50290,49261,50570,51046,50849,51243,47192,50681,50630,48674,49964,47929,50333,47326,47266,48554,49874,51511,50718,51404,47789,49850,48420,47845,48167,46944,49796,51502,49130,50179,50250,48557,50338,49798,47396,51495,48423,47721,47982,48437,49759,50255,48701,49100,48425,47359,49318,47239,49129,51108,49294,49728,49256,50736,51216,50969,49631,48635,50434,49763,50018,50696,50243,49720,51202,48845,51496,51037,47234,50065,50516,50801,51471,48861,51364,49102,48823,50468,51283,51188,49978,50390,48041,47345,51392,46886,47784,49640,48048,50504,50066,47346,49501,50917,50277,51356,50640,51480,51156,50109,50262,47990,48650,49000,48876,46982,49659,48579,49367,50677,49240,48334,50387,50426,51380,48647,51171,51044,51347,50070,48783,48336,51153,47225,50700,50001,49954,48654,50173,50305,50024,48310,50152,50377,48400,51082,48448,50478,50847,50526,50929,47785,47973,49707,50785,50654,49688,47629,50739,49217,50059,50007,51405,48439,49774,50021,50628,51118,49822,46817,47989,50932,49214,50557,47333,50769,49923,51421,51447,50826,50702,50006,50993,48001,49712,49705,49706,50464,48348,50169,48815,51233,50884,49354,50437,51520,49264,50821,50230,50310,48917,50759,47349,50268,47211,50135,47219,51531,49692,48240,50944,47445,50036,50995,48177,50082,48795,47922,50614,51252,49221,50138,48326,51076,48507,47994,50029,51155,49502,51519,49603,50760,50185,50143,47034,49751,50952,49237,50361,50918,48652,50946,49637,48003,48819,50071,50191,51229,47397,47733,50869,48052,51014,49534,50830,50764,49559,49865,48615,48376,50813,51323,49768,50548,49962,51552,50172,47338,49401,50593,49848,47999,50301,51126,47222,47288,48688,48279,51067,50469,49630,50079,49395,49726,48109,50167,48105,50439,49097,49408,51209,47974,48321,51491,50181,50671,46751,48117,47337,50547,49802,51507,50259,48277,50887,51172,50265,50153,51015,51077,51081,51099,51010,51017,51521,51022,51036,51053,51018,51547,48272,51264,48304,51004,51093,50524,50968,51368,47325,50072,51193,49767,50494,50012,50028,50039,49001,50786,49979,47334,49785,50182,51513,50947,50767,48122,50242,48388,49558,49783,49658,49661,48180,47938,48622,49464,50817,49944,48452,50960,50513,47067,50188,48247,48841,50187,50685,50399,46940,51020,49817,51050,48347,46906,48187,47607,50866,51493,50737,49409,50150,47265,50604,47361,48090,51251,49855,50833,50782,48098,46882,48857,51338,49875,49739,50749,50342,48522,48443,49700,50763,49621,50283,51025,48578,50725,51549,49125,47384,50362,50575,50998,51551,50425,51047,50341,50889,50450,48581,50501,51072,51166,49881,50180,46980,48633,47038,49458,50738,48569,50340,49110,47730
        // 52038,54000,52382,51949,52255,52258,51723,52056,53998,51780,51690,52650,52685,51653,52696,52350,53132,52931,51954,53466,52151,53351,53027,52574,53511,52982,51748,53364,52617,52567,51895,52703,53536,53815,54010,53685,53037,53180,53666,53374,52638,54189,52688,53641,51752,54257,52160,51640,54134,53142,51816,52532,51891,54415,52210,51654,53287,52577,52313,52355,52535,52040,51873,52198,52609,53079,53910,52785,54197,53156,53877,52300,53960,54288,52325,53297,52720,52005,51940,52984,54185,54162,52025,54145,52218,53182,53183,53026,52718,53637,52738,53032,52885,52634,51633,54407,52096,52425,53964,54263,51978,52011,53430,53811,52008,51669,54379,53900,52520,53235,51607,52269,52084,54294,53389,53040,53274,52831,51629,52944,54342,54245,53198,52260,53967,52915,52929,54453,53006,53460,54353,51858,51737,54205,52217,53515,53703,53388,53324,52730,53958,52079,53901,51684,51861,52926,54077,51851,52803,52463,54090,51686,54063,52561,52806,53023,51912,52690,54139,53746,52467,51918,53052,52083,52376,54308,54350,52435,53450,54438,54125,53565,53710,52073,53867,52760,53337,52819,53601,51651,54161,51890,52962,53184,51562,53195,54281,52305,54321,52562,52989,52515,52068,54059,52039,51667,54328,53279,53424,51758,51735,51593,51580,53105,51934,53409,52887,53122,52618,51929,53022,52457,52173,52505,54304,51920,52060,53558,52117,53335,52273,52353,52165,54085,52921,52759,52507,52963,54031,53658,53064,52624,53451,53783,54370,54454,53236,51769,52559,52405,53743,53373,52116,52027,53793,52903,52246,53655,52115,53008,52485,53456,51589,51869,54318,53188,51819,52753,54312,53333,52139,52454,52331,52846,52919,53890,52375,52394,52874,52021,53097,51734,52896,51718,54027,51698,51894,54348,52275,53564,52643,53035,54369,53387,54227,53028,53082,52449,52552,53506,52464,51609,54073,54393,53806,52512,52271,52586,52413,52575,53645,51750,52521,52769,51786,53417,53490,52451,52142,52158,54216,53073,53066,51681,53208,53539,52994,52214,52409,52758,54194,53434,53160,54012,52848,52329,54002,52148,53316,53889,52540,51701,53782,54203,52470,52554,53504,53514,51625,53030,53138,54388,51900,54419,53513,51592,51642,52346,53015,53986,51988,53555,54333,53845,54428,54443,53650,54004,52548,51833,53185,51570,53904,51825,52285,52948,53530,52805,52270,52882,51670,54074,52022,54044,51720,53014,53527,51942,52908,54373,51725,52578,53679,53100,52707,54249,54019,52799,52587,53116,52349,52927,54430,52411,54173,54250,53176,53689,54121,52686,52262,52229,51882,53412,53771,52788,52891,52835,54172,51803,52810,53985,51815,52744,52665,51672,54262,53484,53832,52786,53706,51806,52164,53716,52219,52501,52807,52446,52947,52267,52924,51902,53814,54336,52729,52465,53590,53486,52899,53269,52312,52001,52639,52490,52904,51847,54092,54097,54392,53611,51931,51643,52389,52764,51747,52845,53700,54089,53164,53403,53225,53935,52444,53686,53912,52599,51976,52187,51563,51888,52541,51856,53508,53810,52677,52495,52838,53997,53226,53870,54158,54449,51564,52381,51605,53946,51664,53749,53604,54229,53392,52704,52875,52855,53895,51613,52648,54040,51649,51645,53872,53289,53477,53829,54144,52396,53507,53726,51688,53636,54247,52995,53391,53949,51923,53314,52126,51704,51981,52518,54182,53775,52138,51878,53200,52843,52082,52890,54015,53747,52276,52287,53384,52236,53563,53835,53534,52113,53095,52136,52640,54417,52373,52213,54384,54403,54179,53973,53661,53021,54378,51661,54285,54046,51779,53438,53407,52582,52081,52879,51631,52884,53469,51567,51813,52663,51957,51989,52323,54433,53881,51687,53125,51800,53903,52949,52597,52043,51657,51586,52775,53113,54088,52876,53825,54375,52830,53428,53533,53341,53959,52466,53261,53559,51700,53049,51945,51994,52182,54183,54354,51901,53695,52317,52861,54253,54071,53879,54447,54231,52570,53446,54033,51641,53896,54408,51727,53919,52724,53173,53897,53300,52152,54420,54418,53497,52417,51870,53092,53615,51807,52864,54184,52938,52462,53087,53622,54444,51943,54367,54446,52111,54299,51770,53755,52124,54001,53206,52790,53769,52687,51933,52178,53440,54034,53662,53357,51572,53467,54232,53350,54174,54368,53816,52913,54272,54212,52865,51887,53733,54351,54242,52850,51915,52335,52723,52266,51577,52736,52497,52196,52632,53607,54091,52517,52883,52804,53854,54112,52933,53785,52163,52615,52671,51763,53329,51731,53277,54383,53401,52641,51615,53070,54207,53808,52225,52157,53293,52777,51804,53995,52878,54398,53701,54376,54255,53088,52834,52093,53038,51961,52536,51590,53740,53193,52942,54401,53676,53711,52337,53812,53068,52917,53614,53621,52439,52493,51662,51979,52610,54329,52067,52800,52061,52169,53478,53927,51922,53634,51971,51742,54254,54038,53104,51986,54154,54200,52604,53612,54128,54343,52808,52143,53362,53044,52629,53238,53869,53836,53320,54159,52123,53158,52369,52034,52952,52264,54214,52161,52969,53578,54171,53807,52752,52593,53346,52250,54425,53338,54334,51599,52170,52930,51663,52286,53399,53741,54423,52134,51666,52702,54029,51969,53209,53885,52263,53804,51675,51676,53751,51862,54146,52338,51658,52824,53994,52358,51822,53987,52565,53843,53857,53809,53894,53591,52527,54045,52094,53909,51745,52479,53231,53663,53445,52537,52077,52996,51674,51928,53076,53729,51832,54170,54251,52576,53272,54101,52596,52453,52154,54330,52496,51736,52388,53571,52303,54260,53525,52817,52133,52847,54215,54306,53624,54235,53943,52503,53581,53084,54199,53939,53777,51754,53131,52244,51768,53922,52223,53085,52791,52555,53841,53048,53147,52441,53187,53742,52922,51594,52370,53597,52613,51796,53898,54014,51968,53865,52737,53654,52202,52200,51846,54110,52057,52201,54026,52991,52242,53254,52168,53094,52676,51732,52086,54021,53065,52253,52692,51638,53041,54141,52709,54236,53532,53267,51904,54107,53549,54079,54100,54093,52666,51826,51829,53367,53608,52623,52448,53791,54339,54372,53859,52235,52135,54252,53155,52289,52920,53873,52739,51947,52977,53406,54008,54400,52595,53725,53628,53004,54338,52404,52993,53211,54340,52680,51715,51761,51755,51777,51614,53161,52867,53494,54096,51596,52105,52880,52288,52412,53593,52823,52818,53108,54313,51793,51766,53221,51965,54084,54347,54105,53717,53482,52784,52315,53851,54230,54434,52842,53089
        // 53768,53228,53114,52429,54317,54233,52179,54186,52402,54435,52257,54069,51617,52918,53944,53704,53659,53638,54036,52408,51967,51857,52374,52088,53962,53476,54259,52894,54422,51765,52047,52900,52481,53821,52175,51802,52916,51787,54431,53294,53582,51602,52297,53855,53413,53502,52427,53368,51597,54440,53352,54060,52473,52397,51650,51964,52299,52018,53475,51691,52869,53296,53778,53281,51717,53459,53776,53780,54083,54268,53018,51970,54282,51930,54095,54275,52186,51795,53312,51805,52606,53166,52710,53251,53455,53063,53394,52028,52815,54078,51585,53452,51962,54256,52580,51730,52282,54018,51898,51955,54157,52935,53461,52308,53853,53516,52249,52631,51913,52770,52129,52046,52131,51724,54020,52754,51854,52872,51623,54280,53600,53178,51591,54331,54130,54009,53290,54042,52003,53268,53232,53432,51946,52410,54006,52526,53011,51604,52519,52902,52719,52727,53275,53435,54030,51696,52906,52572,54325,51886,51668,52542,53444,53518,54310,53310,53605,53233,51798,51908,54240,51665,52100,54102,53159,53568,53134,52090,53863,53137,54024,54442,52626,51644,53818,52357,53966,52740,53043,52955,52030,52839,52833,52844,51778,52822,53319,53623,53619,53003,53569,53110,53332,51630,54003,53678,51921,53230,52504,53521,51852,54178,54409,51733,54441,52211,52649,51637,52661,54037,52033,51828,52452,52017,52733,51958,52951,52443,53823,51652,52893,53981,52990,53306,52292,53926,53302,52827,51709,53955,52975,54349,53668,52050,54168,54399,53123,54326,51990,51757,53083,54211,52334,54035,52197,54150,52988,54315,53411,53547,52628,52684,53219,53096,53448,52455,52633,51801,52063,53301,52997,53756,54391,53567,53025,52670,53893,52026,53575,54196,53055,52037,52127,54106,53139,53598,52014,53675,53410,53442,53416,53644,54133,54048,52341,52705,51722,53240,53990,54248,51839,51620,52717,51739,54374,52150,51855,54377,52771,53583,52772,53781,52491,53433,53842,53707,52892,53210,53911,52176,53465,53488,51952,51568,51899,53090,53993,52112,52741,53722,51788,51831,52714,52716,52322,51616,54166,52380,54143,53140,54287,53803,52689,53191,52483,52712,52316,53419,53345,52024,51764,52897,53499,53151,53837,52118,53045,53673,51925,53705,52122,53669,54122,53933,53334,52239,52660,52853,52851,53914,52351,53796,52768,53522,53868,53024,51574,54412,52009,54208,52932,53308,53629,53744,52551,52546,52226,52658,53542,53670,52193,53573,53992,53738,51911,51569,51726,52774,53192,52120,54278,54246,51714,52782,52589,53984,53971,52372,53763,53878,52585,54307,53146,53295,53524,53779,52773,53915,51916,52523,51782,53154,53370,51679,52928,52474,52212,54335,53719,53234,52598,52862,53858,51984,53613,51982,52053,52283,54332,52781,54352,51576,53639,53748,51677,51743,53376,54323,53353,53680,54123,53129,53772,52608,53828,53386,53802,52074,53999,53057,52958,52415,53239,52757,51716,52080,52583,52064,53144,51907,53848,52137,52792,53684,53119,51880,51632,53439,52172,54385,52327,51919,51905,54357,51775,51578,52571,54284,53498,52849,52778,52821,53101,53699,54193,52440,52147,54028,53036,51818,51836,52469,53252,52780,53423,54080,53570,53336,53735,54387,53509,53237,51634,51622,52345,52711,53307,54099,51893,53317,53369,52324,53520,52700,53831,53288,52162,53977,53767,53363,53462,52240,51985,54068,53222,53009,54327,54291,53426,53945,53344,52939,54413,52340,54108,51935,53702,53150,51703,51707,52731,51708,51840,53080,52284,54011,51636,54309,51993,52979,51896,54258,54358,54032,53681,53720,52530,52188,53864,54361,52525,52477,53172,53375,52943,52310,53220,54076,52621,54266,53382,54013,53632,54264,52015,53186,53968,52460,53936,52999,52167,53758,54164,51582,52247,54113,52190,53574,52174,53978,53340,53165,53688,53557,52881,52280,53697,53303,52330,51884,52078,52426,53694,54181,54190,54302,53349,52291,54219,52668,53175,53965,54296,52234,52901,53190,52406,54359,53531,53431,52183,52511,52006,53501,54056,52836,53556,54142,52657,53646,52121,54082,51924,53179,51794,53856,53242,52751,53916,53256,51694,52277,52476,52960,53953,52108,54192,53617,52656,51999,54356,52499,53472,52140,53866,51573,51906,51938,51917,52423,53059,54149,51998,53963,52272,52619,52328,52644,53888,53602,52652,54397,53118,53257,52398,53378,51738,52840,53860,54426,54204,52020,52391,52261,53715,51624,53713,52265,52180,52010,53626,51948,54210,53952,52528,54050,53930,53213,51746,52243,53437,52141,53908,53721,52471,53660,53517,52144,52480,52336,53325,54324,52706,52662,52545,52384,51729,53550,52945,52099,54188,53672,54023,53618,51843,51575,51868,53579,53422,52654,52934,53625,52377,52049,51606,54414,52487,53365,52227,53546,52107,52502,53577,51671,52553,53454,52564,52895,52062,53766,52486,53099,53989,53493,52959,51937,52458,52713,53276,51866,53315,52042,53177,54269,53991,53934,53427,52222,52811,51876,53687,53754,52087,54058,52359,52461,53880,52787,52233,53214,53876,52794,54395,52594,53874,52259,53937,52386,53665,52450,52367,51865,52007,53012,52045,52637,52494,53400,52395,52715,54283,54061,53280,52907,54049,52478,53354,52110,51587,52307,53170,52071,54389,53001,54156,53062,54094,53342,51845,54270,53265,53050,53263,52433,53171,52533,53194,51646,53609,54360,53974,53148,53167,54390,52981,54322,51842,51864,52207,52189,52980,52820,54152,52364,52098,52762,54165,51792,54421,54344,53932,53496,54066,54098,52051,53902,52856,52601,51817,53071,53834,52936,52563,53727,52319,54191,53273,51626,52588,53115,52622,53408,52419,53714,54429,53799,54177,52538,53736,53871,52171,54087,51685,51987,53007,51863,52475,54163,53924,52089,52866,53464,52950,52206,54136,53284,53402,53250,52054,53827,54206,54148,53510,51996,52091,53752,53216,51566,53060,52387,53328,52035,53975,51712,52392,51655,53485,51682,53366,52863,52828,52237,51883,52366,52513,52560,52209,52002,52177,51877,52607,54065,53058,51897,54406,54286,53168,52614,53519,52795,52298,52659,52224,52445,53245,54103,53786,52181,54055,53218,54451,51773,53664,53920,51772,53425,53107,53774,53849,51909,52549,54187,53765,53566,51814,52747,52767,52914,53111,53480,53248,53405,52940,52245,53495,52195,54111,52097,51751,54140,52531,54104,51692,53899,52256,53321,53042,51753,52812,53692,51741,52432,52841,52130,53204,53385,53753,52145,54132,54277
        // 53957,52401,51581,54209,54124,54456,51871,52605,53174,53790,51812,52667,52459,54319,52069,53322,52348,54043,52558,52635,54025,51910,52293,54314,53103,54109,52153,53436,51849,52976,52612,54380,54201,53745,52132,52339,54116,53788,53379,52653,51719,52678,52961,54114,52627,52492,52694,53479,53584,53976,51583,51838,53923,54337,51932,52732,51953,51972,51705,52302,52194,52543,51809,52748,53072,54057,52966,52318,51835,52683,52065,52314,54075,54265,53732,54117,51699,52489,53463,52326,54047,53594,53728,52826,53339,54452,52978,53905,52052,52185,54239,54276,54169,53691,51811,53929,53483,52166,52636,53913,53474,54450,53800,52986,52041,53891,53928,52750,53640,52420,52701,51635,52295,53415,53794,52241,52602,52968,54213,52699,52946,53285,52749,52125,54226,53526,52156,52216,54054,53562,52215,51927,53886,53229,54365,53299,52873,53708,53787,51853,52566,52385,54455,54051,53596,52953,54362,54293,52407,53587,52159,52516,54411,53606,54016,53651,53552,53355,53246,52603,52221,51889,53861,53067,53683,52725,54222,53005,51867,52992,53538,53117,52642,53404,53286,51881,52238,52973,53817,52347,52970,51689,52779,54346,53956,52228,53112,53091,52579,52434,52722,54138,51710,51944,52888,52529,53739,51823,52957,54131,52321,52509,54135,51693,52128,52672,52428,53633,53970,52923,53449,52681,53128,52013,53075,54224,51619,52655,52004,53330,52825,51830,53145,51706,52019,52522,53162,54439,54137,51960,52344,52424,53311,53731,54355,51872,52557,51610,53798,52954,53512,53383,53212,51941,53820,54053,53983,53149,52378,53770,52854,53718,53792,53002,53047,53380,52510,51771,52488,53243,52294,54295,53468,52016,52796,53305,52418,53690,52309,51579,54234,53630,51791,54007,52232,53840,54382,54155,54316,52048,51601,53153,53169,52645,52072,54341,53883,51785,53730,54386,54147,51781,53359,53420,53418,53077,52814,52698,52721,53197,51697,51600,53013,52399,52909,54070,53696,52365,54300,54220,54241,53264,52230,52371,52085,53589,52101,51659,54297,53121,53554,52837,53199,52611,52044,52301,53278,52871,51618,53126,53136,52742,53481,53503,53457,53201,54267,54448,52674,52675,51903,53429,52898,52860,52556,51588,51859,54118,52972,52191,51565,52075,54366,53649,52669,52745,52679,51950,53120,53833,52281,53371,53844,52971,53414,52983,53358,53887,52789,54445,51678,51821,53381,52584,52278,51621,52421,53813,51973,53917,52695,52801,54064,53610,52484,52343,52103,51844,53227,53693,51983,51914,52591,52352,53390,53217,54298,53181,53271,53931,52109,53247,52354,51885,54115,53143,54223,51860,54005,53102,52437,52472,52114,54274,53356,53010,53850,53266,51991,51598,53839,54305,52368,51627,53988,52508,53255,53862,53592,52911,54217,53652,52332,52333,52590,52436,53548,53130,52383,52965,53941,51995,52296,52058,53078,51820,54364,53528,51808,52500,53948,52029,53847,54072,53487,52506,54127,54022,53656,54067,51959,53643,51850,52682,53819,53360,52726,53253,52697,53969,54041,54017,51799,52964,53500,53795,52414,52956,53947,52403,53505,53698,52550,53157,52802,52544,54221,53674,53826,53723,53576,52320,51608,53529,52673,52630,53492,54427,52829,53441,53603,52220,53223,52868,53086,51784,52205,54052,53224,51879,54320,51783,52858,53635,52254,53127,54432,52937,52743,53762,52231,53215,54261,53034,53304,52766,54416,51695,53196,53348,53244,53447,52664,51997,53642,52055,52208,52756,53541,54039,53372,52000,52708,54198,52547,51749,52905,53709,54180,52763,52104,53616,54301,51810,52793,53046,54160,52647,53620,51673,54129,51683,51824,53292,51966,53326,51728,52251,51874,51639,52059,53805,52728,53458,53202,54404,54396,51603,53789,52941,52765,52985,53124,53309,52199,54371,53453,53599,53054,51571,54243,52889,51648,54195,53940,51977,54151,53540,53523,53830,54228,53560,53313,53671,53972,52859,51647,53906,52514,54175,51797,54237,53098,52342,53470,52573,53588,52416,54424,53712,52910,53291,52877,52379,54086,54126,53647,53980,53979,51656,53925,52095,51660,51992,52023,52422,51963,53000,53205,52248,53631,52468,52306,52070,53203,52651,52012,51875,51762,52268,51702,53875,52813,53750,52311,53677,53327,51721,54279,53801,52204,52735,54345,51756,52569,51759,52987,52482,51892,51936,52356,53846,53657,53421,53907,53397,54153,53141,51595,54290,52776,53260,53724,53773,53106,53270,52581,53553,53298,52925,52691,53361,53938,53283,52106,53882,51584,53241,52390,52616,53398,51827,51848,52031,53595,53343,53961,52600,53491,52797,53051,53258,54081,54410,54167,51926,54311,53489,53074,53017,54381,54405,53734,52816,52438,51975,52620,52974,51767,54238,52886,52447,53737,54289,54292,52783,51628,53109,54303,52568,52203,51680,51956,52279,53163,51834,52870,53029,52032,51841,51776,53347,52304,52036,52361,52693,53667,52431,54394,54273,53093,52852,53572,51789,52442,52912,52155,54120,54225,52498,52857,53282,51951,53852,53033,53784,51790,53561,53951,52252,53797,51744,53921,53918,52146,52734,52539,52360,51713,53942,51774,53586,53395,53396,53039,53031,52102,52755,54119,52290,51740,53259,53892,52076,53133,52998,53323,53954,53331,53537,53471,52534,52363,54062,52625,52192,51711,54176,52832,53249,52798,52149,51980,52592,52967,54244,53585,53056,53377,54363,52184,53996,53443,52092,54202,54271,53950,53473,53757,52524,53682,53535,53152,53653,53053,52456,52393,51837,52430,53318,53135,51974,53069,53824,52066,53189,53016,53884,53982,52746,52809,52400,53648,53207,53551,53081,53061,53580,52362,53393,53838,53262
    }
}
